package com.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Dao.ProcDao;
import com.google.gson.Gson;
import com.pojo.Sight;


@WebServlet("/procCtr")
public class ProcController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");	
		response.setCharacterEncoding("utf-8");
		String huifu = request.getParameter("datax");
		Integer SId= Integer.valueOf(request.getParameter("id"));
		Integer UId= Integer.valueOf(request.getParameter("uid"));
		ProcDao ProcDao =new ProcDao();
		Integer count = 0;
			try {
				count = ProcDao.save(UId, SId, huifu);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		Sight[] sight = new Sight[100];
		try {
			sight = ProcDao.findAllGart(SId);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Gson gson = new Gson();
		String jsonStr = gson.toJson(sight);
		PrintWriter out = response.getWriter();
		out.print(jsonStr);
	}
}
